Overview

As with any coding project, you’ll want to upload your work to a GitHub repository so that you can access different versions as needed and facilitate collaboration. You will clone the GitHub repository to your machine and push your code at the end of each exercise during this course.

Note: You must work through the Recap: Version control lesson item in this course prior to completing this exercise.

Scenario

Before you get started on the Little Lemon food ordering app, you'll need to establish a place for the project to reside. In this exercise, you will create a repository on GitHub, clone it to a local repository, add a test file and commit the changes.

Instructions

Step 1

Download and install Git for your operating system and architecture from the Git downloads page .

Note: Make sure to select the version that is designed for your machine’s operating system.

Step 2

Note: The image below displays an example of a repository name for demonstration purposes.

Step 3

Open the Git terminal on your machine.

Step 4

Copy the URL for your newly-created GitHub repository.

Note: The image below displays an example URL for demonstration purposes.

Step 5

Make a new directory for the local repository by typing the following line in the terminal:

$ mkdir little-lemon

Step 6

Enter the directory by typing the following line in the terminal:

$ cd little-lemon

Step 7

Paste the copied URL in the git clone command as demonstrated below (use your URL in place of the example URL):

$ git clone https://github.com/coursera/little-lemon.git 

Tip: This will initiate the cloning process and produce output similar to what is shown below:

Step 8

Enter the repository and check the list of files. If the cloning process is successful, you should have a list like the following:

$ cd little-lemon

$ ls -la 
total 5 
drwxr-xr-x 1 ********** 4096  0 Dec  2 09:58 ./ 
drwxr-xr-x 1 ********** 4096  0 Dec  2 09:58 ../ 
drwxr-xr-x 1 ********** 4096  0 Dec  2 09:58 .git/ 
-rw-r--r-- 1 ********** 4096 14 Dec  2 09:58 README.md 

Step 9

$ vi newfile.txt

Step 10

Check the Git status using the $ git status command.

$ git status 
On branch main 
Your branch is up to date with 'origin/main'. 
Untracked files: 
  (use "git add <file>..." to include in what will be committed) 
        newfile.txt 

nothing added to commit but untracked files present (use "git add" to track) 

Step 11

Add the newfile.txt to the stage with the $ git add command.

$ git add newfile.txt

Step 12

Commit the changes with the $ git commit command.

$ git commit -m "first commit"

Step 13

Check the status again with the $ git status command.

$ git status 
On branch main 
Your branch is ahead of 'origin/main' by 1 commit. 
  (use "git push" to publish your local commits) 
  
nothing to commit, working tree clean 

Step 14

Push the changes with the $ git push command.

$ git push origin main 
Enumerating objects: 4, done. 
Counting objects: 100% (4/4), done. 
Delta compression using up to 8 threads 
Compressing objects: 100% (2/2), done. 
Writing objects: 100% (3/3), 294 bytes | 294.00 KiB/s, done. 
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 
To https://github.com/malharSS/first-repo.git 
   7ecff08..44d2a2e  main -> main 

Note: You may be required to enter your GitHub username and password.

Step 15

Step 16

Finally, go back to Git bash shell and pull the repository to update the local repository, using the $ git pull command.

$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 686 bytes | 14.00 KiB/s, done.
From https://github.com/malharSS/first-repo
   44d2a2e..091e422  main       -> origin/main
Updating 44d2a2e..091e422
Fast-forward
newfile.txt | 1 +
1 file changed, 1 insertion(+)

Conclusion

In this exercise, you created a GitHub repository and cloned it as a local repository on your machine. You then added a file and committed the changed status, and pushed the changes back to the remote repository. After making changes remotely, you pulled it to update the local repository.